﻿using System;
using System.ComponentModel;
using System.Web.UI;
using PortalCurriculo.WebUI.Helpers;

namespace PortalCurriculo.WebUI.UserControls.Basico
{
    public partial class Popup : UserControl
    {
        [Browsable(false)]
        [DefaultValue(null)]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public virtual ITemplate Formulario { get; set; }

        public string ValidationGroup { set { btnSalvar.ValidationGroup = value; } }
        public string Titulo { set { lblTituloPopup.Text = value; } }

        #region Eventos

        private static readonly object SalvarEventClick = new object();
        protected virtual void OnSalvarClick(EventArgs e)
        {
            var onClickHandler = (EventHandler)Events[SalvarEventClick];
            if (onClickHandler != null) onClickHandler(btnSalvar, e);
        }
        public event EventHandler SalvarClick
        {
            add
            {
                Events.AddHandler(SalvarEventClick, value);
                btnSalvar.Click += value;
            }
            remove
            {
                Events.RemoveHandler(SalvarEventClick, value);
                btnSalvar.Click -= value;
            }
        }

        private static readonly object CancelarEventClick = new object();
        protected virtual void OnCancelarClick(EventArgs e)
        {
            var onClickHandler = (EventHandler)Events[CancelarEventClick];
            if (onClickHandler != null) onClickHandler(btnCancelar, e);
        }
        public event EventHandler CancelarClick
        {
            add
            {
                Events.AddHandler(CancelarEventClick, value);
                btnCancelar.Click += value;
            }
            remove
            {
                Events.RemoveHandler(CancelarEventClick, value);
                btnCancelar.Click -= value;
            }
        }

        #endregion

        protected override void OnInit(EventArgs e)
        {
            Formulario.InstantiateIn(divFormulario);
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public void Show()
        {
            PopupControl.Show();
        }

        public void Close()
        {
            PopupControl.Close();
        }

        protected void btnCancelar_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}